<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }

        .register-container {
            background: white;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 450px;
        }

        .register-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .register-header h1 {
            color: #333;
            font-size: 28px;
            margin-bottom: 10px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: bold;
            font-size: 14px;
        }

        .form-group input {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        .form-group input:focus {
            outline: none;
            border-color: #4CAF50;
        }

        .error-message {
            color: #ff4444;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }

        .btn-register {
            width: 100%;
            padding: 12px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
            margin-top: 10px;
        }

        .btn-register:hover {
            background-color: #45a049;
        }

        .login-link {
            text-align: center;
            margin-top: 20px;
        }

        .login-link a {
            color: #4CAF50;
            text-decoration: none;
        }

        .login-link a:hover {
            text-decoration: underline;
        }

        .field-requirements {
            font-size: 12px;
            color: #666;
            margin-top: 4px;
        }
    </style>
</head>
<body>
    <div class="register-container">
        <div class="register-header">
            <h1>用户注册</h1>
            <p>创建您的账户</p>
        </div>

        <!-- Django 错误消息显示 -->
        {% if messages %}
            {% for message in messages %}
                <div class="error-message" style="display: block; text-align: center; margin-bottom: 15px;">
                    {{ message }}
                </div>
            {% endfor %}
        {% endif %}

        {% if form.errors %}
            <div class="error-message" style="display: block; text-align: center; margin-bottom: 15px;">
                请检查您的输入信息
            </div>
        {% endif %}

        <form method="post" action="{% url 'user:register' %}">
            {% csrf_token %}

            <div class="form-group">
                <label for="username">账号</label>
                <input type="text" id="username" name="username" required
                       placeholder="请输入用户名" value="{{ form.username.value|default:'' }}">
                {% if form.username.errors %}
                    <div class="error-message" style="display: block;">
                        {{ form.username.errors.0 }}
                    </div>
                {% endif %}
            </div>

            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required
                       placeholder="请输入密码">
                {% if form.password.errors %}
                    <div class="error-message" style="display: block;">
                        {{ form.password.errors.0 }}
                    </div>
                {% endif %}
            </div>

            <div class="form-group">
                <label for="confirm_password">确认密码</label>
                <input type="password" id="confirm_password" name="confirm_password" required
                       placeholder="请再次输入密码">
                {% if form.confirm_password.errors %}
                    <div class="error-message" style="display: block;">
                        {{ form.confirm_password.errors.0 }}
                    </div>
                {% endif %}
            </div>

            <button type="submit" class="btn-register">注册</button>
        </form>

        <div class="login-link">
            <p>已有账号？<a href="{% url 'user:login' %}">立即登录</a></p>
        </div>
    </div>
</body>
</html>